<template>
  <div class="auth-container">
    <!-- 认证表单容器 -->
    <div class="auth-wrapper">
      <!-- 切换按钮 -->
      <div class="auth-tabs">
        <button 
          class="tab-btn" 
          :class="{ active: currentView === 'login' }"
          @click="switchView('login')"
        >
          登录
        </button>
        <button 
          class="tab-btn" 
          :class="{ active: currentView === 'register' }"
          @click="switchView('register')"
        >
          注册
        </button>
      </div>

      <!-- 动态切换组件 -->
      <transition name="fade" mode="out-in">
        <LoginForm 
          v-if="currentView === 'login'"
          @switch-to-register="switchView('register')"
          key="login"
        />
        <RegisterForm 
          v-else
          @switch-to-login="switchView('login')"
          key="register"
        />
      </transition>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import LoginForm from '../components/LoginForm.vue'
import RegisterForm from '../components/RegisterForm.vue'

const currentView = ref('login')

const switchView = (view) => {
  currentView.value = view
}
</script>

<style scoped>
.auth-container {
  min-height: 100vh;
  background: var(--color-background);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
}

.auth-wrapper {
  width: 100%;
  max-width: 500px;
  background: var(--color-background-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  /* 移除边框，只保留阴影 */
  overflow: hidden;
}

/* 切换标签 */
.auth-tabs {
  display: flex;
  background: var(--color-background-soft);
  /* 移除底部边框 */
}

.tab-btn {
  flex: 1;
  padding: var(--space-lg);
  border: none;
  background: transparent;
  color: var(--color-text-light);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

.tab-btn.active {
  color: var(--color-primary);
  background: var(--color-background-card);
  /* 移除底部黑色线条，改用更柔和的指示器 */
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 3px;
  background: var(--color-primary);
  border-radius: 2px;
  /* 添加透明度让线条更柔和 */
  opacity: 0.8;
}

.tab-btn:hover:not(.active) {
  color: var(--color-text);
  background: var(--color-background-mute);
}

.tab-btn:focus {
  outline: none !important;
  border: none !important;
  box-shadow: none !important;
}

.tab-btn:active {
  outline: none !important;
  border: none !important;
  box-shadow: none !important;
}

/* 过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: all 0.3s ease;
}

.fade-enter-from {
  opacity: 0;
  transform: translateY(10px);
}

.fade-leave-to {
  opacity: 0;
  transform: translateY(-10px);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .auth-container {
    padding: var(--space-md);
  }
  
  .auth-wrapper {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
  }
}

@media (max-width: 480px) {
  .auth-container {
    padding: var(--space-sm);
  }
  
  .auth-wrapper {
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
  }
  
  .tab-btn {
    padding: var(--space-md);
    font-size: 0.875rem;
  }
}
</style>
